package org.example;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Test1 {
    //leetcode 429 N叉树的层序遍历
    //https://leetcode.cn/problems/n-ary-tree-level-order-traversal/description/
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> ret = new ArrayList<>();
        if (root == null) return ret;
        Queue<Node> queue = new ArrayDeque<>();
        queue.add(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                Node parent = queue.poll();
                list.add(parent.val);
                for (Node node : parent.children) {
                    queue.add(node);
                }
            }
            ret.add(list);
        }
        return ret;
    }

    public static void main(String[] args) {
        Queue<Integer> queue = new ArrayDeque<>();

    }
}
